﻿using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

using IfSoft.OA.Entities;

namespace IfSoft.OA.DataAccess
{
    public class UserMap : EntityTypeConfiguration<User>
    {
        public UserMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties           
            this.Property(t => t.UserName)            
               .HasMaxLength(50);           

            // Table & Column Mappings
            this.ToTable("User");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.UserName).HasColumnName("UserName");                   
            this.Property(t => t.Password).HasColumnName("Password");
            this.Property(t => t.Email).HasColumnName("Email");
            this.Property(t => t.FullName).HasColumnName("FullName");   
            this.Property(t => t.CreatedTime).HasColumnName("CreatedTime");

            // Relationships
            this.HasMany(t=>t.Roles)
                .WithMany(t=>t.Users)
                .Map(m=>
                    {
                        m.ToTable("UserRole");
                        m.MapLeftKey("UserId");
                        m.MapRightKey("RoleId");
                    }
                   );
        }
    }
}

